<?php

namespace app\index\service;

use app\common\model\AccountTokenActivity;
use app\index\dao\AccountTokenActivityDao;
use app\index\model\UM as UM;

/**
 * Class CoinActivityService
 * @package app\index\service
 */
class CoinActivityService
{
    // dao
    private AccountTokenActivityDao $accountTokenActivityDao;

    public function __construct(AccountTokenActivityDao $accountTokenActivityDao)
    {
        $this->accountTokenActivityDao = $accountTokenActivityDao;
    }

    /**
     * 未参数的活动详情
     * @param UM $user
     * @param array $params
     * @return AccountTokenActivity|null
     */
    public function read(UM $user, array $params): ?AccountTokenActivity
    {
        $memberId = $user->id;

        // 非律师 && 不是审核中
        if ($user->type != 1 && $user->isSettled == 0) {
            return null;
        }

        $tableName = AccountTokenActivity::getTable();

        return AccountTokenActivity::leftJoin('account_token_gift atg', "$tableName.id=atg.accountTokenActivityId and atg.memberId=:memberId", ['memberId' => $memberId])
            ->whereNull('atg.memberId')
            ->tableField(true, $tableName)
            ->find();
    }


}
